package com.ruoyi.framework.config;

import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.type.TypeHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.mybatis.spring.boot.autoconfigure.SqlSessionFactoryBeanCustomizer;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;

import java.util.List;

@Configuration
@MapperScan(value = "${mybatis.mapperPackages}", sqlSessionTemplateRef = "sqlSessionTemplate")
public class XbatisAutoConfiguration extends MybatisAutoConfiguration {
    public XbatisAutoConfiguration(MybatisProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider, ObjectProvider<TypeHandler[]> typeHandlersProvider, ObjectProvider<LanguageDriver[]> languageDriversProvider, ResourceLoader resourceLoader, ObjectProvider<DatabaseIdProvider> databaseIdProvider, ObjectProvider<List<ConfigurationCustomizer>> configurationCustomizersProvider, ObjectProvider<List<SqlSessionFactoryBeanCustomizer>> sqlSessionFactoryBeanCustomizers) {
        super(properties, interceptorsProvider
            , typeHandlersProvider, languageDriversProvider, resourceLoader
            , databaseIdProvider, configurationCustomizersProvider, sqlSessionFactoryBeanCustomizers);
    }

    private static SqlSessionFactory sqlSessionFactory;

//    @Override
//    @Bean
//    @Primary
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        sqlSessionFactory = super.sqlSessionFactory(dataSource);
//        return sqlSessionFactory;
//    }
//
//    @Bean
//    @Primary
//    public SqlSessionFactory getSessionFactory() throws Exception {
//        return sqlSessionFactory;
//    }
}
